package com.lifecycle.builder;

import com.claims.UserClaimsApply;

/**
 * Created by 峥桂 on 2017/6/7.
 */
public class KFCWaiter {
    private MealBuilder mealBuilder;

    public void setMealBuilder(MealBuilder mealBuilder) {
        this.mealBuilder = mealBuilder;
    }

    public Meal construct(UserClaimsApply claimsApply){
        int claimsStatus=claimsApply.getHandlestatus();
        if(checkBegin(claimsStatus)){
            mealBuilder.beginHandler(claimsApply);
        }else if(checkEnd(claimsStatus)){
            mealBuilder.endHandler(claimsApply);
        }else if(checkQuestion(claimsStatus)){
            mealBuilder.questionHandler(claimsApply);
        }
        //准备完毕，返回一个完整的套餐给客户端
        return mealBuilder.getMeal();
    }

    private boolean checkBegin(int claimsStatus){
        if(claimsStatus== ClaimsEnum.FirstAudit.getKey()){
            mealBuilder.getMeal().setCurrentStatus(ClaimsEnum.FirstAudit.getValue());
            return true;
        }else if(claimsStatus==ClaimsEnum.inputting.getKey()){
            mealBuilder.getMeal().setCurrentStatus(ClaimsEnum.inputting.getValue());
            return true;
        }
        return false;
    }
    private boolean checkEnd(int claimsStatus){
        if(claimsStatus==ClaimsEnum.Finished_First_Audit.getKey()){
            mealBuilder.getMeal().setCurrentStatus(ClaimsEnum.Finished_First_Audit.getValue());
            return true;
        } else if(claimsStatus==ClaimsEnum.Finished_Entry.getKey()){
            mealBuilder.getMeal().setCurrentStatus(ClaimsEnum.Finished_Entry.getValue());
            return true;
        }
        return false;

    }
    private boolean checkQuestion(int claimsStatus){
        if(claimsStatus==ClaimsEnum.Finished_First_Audit.getKey()){
            mealBuilder.getMeal().setCurrentStatus(ClaimsEnum.Finished_First_Audit.getValue());
            return true;
        }
        return false;
    }

}